/**
 * Created by Administrator on 2017/9/20.
 */
$(function(){

    //加载验证码的方法
    $.idcode.setCode();
    //上方和右边的导航行为
    $("header > .head_top > .wrapper > ul>li").on("mouseenter", function(){
        $(this).css("background", "white")
    });
    $("header > .head_top > .wrapper > ul>li").on("mouseleave", function(){
        $(this).css("background", "#f2f2f2")
    });
    $("header > .head_top > .wrapper > ul>li:first").on("mouseenter", function(){
        $(this).children("dl").stop().slideDown()
    });
    $("header > .head_top > .wrapper > ul>li:first").on("mouseleave", function(){
        $(this).children("dl").stop().slideUp()
    });
    if($.cookie("myLogin")){
        var cookieArr = $.cookie("myLogin");
        // console.log(cookieArr);
        var newObj = JSON.parse(cookieArr);
        console.log(newObj);
        $(".reg_main form>input").eq(0).val(newObj.uName);
        $(".reg_main form>input").eq(1).val(newObj.uPwd);
    }
    $("#submit").on("click", function(){
        //这里 是验证数据库里面记录是否符合，符合就跳转
        //获取账号和密码，验证-----------------
        var uName=$("input[name='uName']").val();
        var uPwd=$("input[name='uPwd']").val();
        $.ajax({
            type:"post",
            url:"http://127.0.0.1/hz1706/day02/sasa_2_login.php",
            data:{"uName":uName,"uPwd":uPwd},
            success:function (result) {
                console.log(JSON.parse(result));
                console.log(JSON.parse(result)["status"]);
                if (JSON.parse(result)["status"]==1){
                    console.log(JSON.parse(result)["msg"]);
                    $("h3").text(JSON.parse(result)["msg"]+",正在跳转到主页...");
                    setTimeout(function(){
                        window.location.href = "index.html?uName=" + uName;
                    },2000)
                }else{
                    $("h3").text(JSON.parse(result)["msg"]);
                }
            }
        });
    });

});